package com.project.controller;

import com.project.bean.CommentBean;
import com.project.bean.ProductBean;
import com.project.bean.UserBean;
import com.project.service.ICommentService;
import com.project.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("comment")
public class CommentController {
    @Autowired
    private ICommentService service;
    @Autowired
    private IProductService productService;
    @RequestMapping("add")
    public String add(String content, Integer productId, HttpServletRequest req){
        UserBean loginUser =(UserBean) req.getSession().getAttribute("loginUser");
        service.add(new CommentBean(content,loginUser.getId(),productId));
        ProductBean product = productService.findById(productId);
        req.setAttribute("p",product);
        return "/findById.html";
    }
}
